package tests;

import junit.framework.*;
import Model.Task;
import Model.TaskManager;

import org.junit.Before;
import org.junit.Test;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * JUnit test case for TaskManagerTest
 */

public class TaskManagerTest extends TestCase {
	//declare reusable objects to be used across multiple tests
	TaskManager t1 = new TaskManager();
	Date utilDate = new Date();
	Task newtask;
	
	String var1 = "Task 1";
	Date var2;
	String var3 = "Periodic";
	String var4 = "Daily";
	
	public TaskManagerTest(String name) {
		super(name);
	}

	@Before
	protected void setUp() {
	//define reusable objects to be used across multiple tests
		//define reusable objects to be used across multiple tests
		DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
		    
		try { 

		 utilDate = df.parse("15/11/2011");
		 newtask = new Task("Task 1",utilDate,"Type 2");
		 var2 = utilDate;
		 t1.addTask(var1, var2, var3, var4);
			 	 
		 
				} 
				
				catch (ParseException e) {
					e.printStackTrace();
				}
	}

	@Test
	public void testTaskManagerConstructor() {

		TaskManager var0 = new TaskManager();
		assertNotNull(var0);
		
	}
	
	@Test
	public void testNotifyObservers() {
		
		t1.notifyObservers();		

	}
	

	@Test
	public void testGetTasks() {

		assertEquals(t1.getTasks().size(),1);
		assertEquals(t1.getTasks().get(0).getName(),var1);
		assertEquals(t1.getTasks().get(0).getDueDate(),var2);
		assertEquals(t1.getTasks().get(0).getType(),var3);
	}
	@Test
	public void testAddTask() {

		TaskManager var0 = new TaskManager();
		var0.addTask(var1, var2, var3, var4);
		assertEquals(var0.getTasks().size(),1);
		assertEquals(var0.getTasks().get(0).getName(),var1);
		assertEquals(var0.getTasks().get(0).getDueDate(),var2);
		assertEquals(var0.getTasks().get(0).getType(),var3);		

	}
	@Test
	public void testDeleteTask() {
		
		assertEquals(t1.getTasks().size(),1);
		t1.deleteTask(var1);
		assertEquals(t1.getTasks().size(),0);
	}
	@Test
	public void testSetTaskStatus() {

		assertEquals(t1.getTasks().size(),1);
		t1.setTaskStatus(true, var1);
		assertTrue(t1.getTasks().get(0).getDone());
		t1.setTaskStatus(false, var1);
		assertFalse(t1.getTasks().get(0).getDone());

	}
	@Test
	public void testUndo() {

		assertEquals(t1.getTasks().size(),1);
		t1.deleteTask(var1);
		t1.undo();
		assertEquals(t1.getTasks().size(),1);		

	}
	@Test
	public void testRedo() {

		assertEquals(t1.getTasks().size(),1);
		t1.deleteTask(var1);
		t1.undo();
		t1.redo();
		assertEquals(t1.getTasks().size(),0);

	}
}